package cn.shyouchi.wuguanjia.android.utils;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;

import com.jeanboy.cropview.cropper.CropperParams;

/**
 * Created by Eenie on 2016/9/14 11:49.
 * Des：
 */

public class ImageUtil {
    public static void pickFromCamera(Activity activity) {
        Uri cameraCacheUri = Uri.fromFile(activity.getExternalCacheDir()).buildUpon().appendPath(getCameraFileName()).build();
        activity.startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).
                        putExtra(MediaStore.EXTRA_OUTPUT, cameraCacheUri),
                CropperParams.REQUEST_PICK_CAMERA);

    }

    public static void pickFromGallery(Activity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            activity.startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"),
                    CropperParams.REQUEST_PICK_IMAGE);
        } else {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        Intent chooserIntent = Intent.createChooser(intent, "选择照片");
        activity.startActivityForResult(chooserIntent, CropperParams.REQUEST_PICK_IMAGE);
        }
    }

    private static String getCameraFileName() {
        return "cropper_" + System.currentTimeMillis() + ".jpg";
    }





}
